package com.jinzecloud.reportapproval.service.impl;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.template.TemplateException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.jinzecloud.reportapproval.bean.*;
import com.jinzecloud.reportapproval.dto.Param;
import com.jinzecloud.reportapproval.mapper.CoverMapper;
import com.jinzecloud.reportapproval.service.CoverService;
import com.jinzecloud.reportapproval.utils.*;
import com.jinzecloud.reportapproval.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("cover")
public class CoverServiceImpl extends ServiceImpl<CoverMapper, Cover> implements CoverService {
    @Override
    public PageUtils queryPage(Param param) {
        String pageSize = param.getPage();
        String limit = param.getLimit();
        String key = param.getKey();
        Map<String, Object> params = new HashMap<>();
        params.put("page",pageSize);
        params.put("limit",limit);
        IPage<Cover> page = this.page(
                new Query<Cover>().getPage(params),
                new QueryWrapper<Cover>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Object> getCovers(Integer prId) {
        List<Cover> covers = this.list(new QueryWrapper<Cover>().eq("info_id", prId));
        List<Object> collect = covers.stream().map(item -> {
            Map<String, Object> map = new HashMap<>();
            map.put("name", item.getName());
            map.put("value", item.getValue());
            return map;
        }).collect(Collectors.toList());
        return collect;
    }

}